package leetCode;

/**
 * 485. 最大连续 1 的个数
 * https://leetcode.cn/problems/max-consecutive-ones/description/
 */
class Solution2 {
    public int findMaxConsecutiveOnes(int[] nums) {
        int left = 0, right = 0;
        int n = nums.length;
        int len = 0;//最大连续1的个数
        while(right < n) {
            if(nums[right] != 0) {
                len = Math.max(len, right - left + 1);
                right++;//进窗口
            } else {
                //nums[right] == 0;
                //出窗口
                while(left != right) {
                    left++;
                }
                left++;
                right++;
            }
        }
        return len;
    }
}